
package com.huaweicloud.saaslanding.install.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 功能描述
 *
 * @since 2023-04-24
 */
@Component
public class DomainNameUtil {

    /**
     * 配置文件中的域名
     */
    private static String confDomainName;

    /**
     * 企业名称
     */
    private static String tenantName;

    @Value("${saaslanding-install.domain.name}")
    public void setDomainName(String domainName) {
        DomainNameUtil.confDomainName = domainName;
    }

    @Value("${saaslanding-install.org.name}")
    public void setUserName(String tenantName) {
        DomainNameUtil.tenantName = tenantName;
    }

    public static String getDomainName() {
        String[] domains = confDomainName.split("\\.");
        if (domains.length == 2) {
            return tenantName.concat(".").concat(confDomainName);
        }
        return tenantName.concat(confDomainName.substring(confDomainName.indexOf(".")));
    }

}
